import requests
from lxml import etree

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWe'
                  'bKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36'
}


def getHTMLText(start_url):
    try:
        r = requests.get(start_url, timeout=30, headers=headers)
        r.raise_for_status()
        r.encoding = 'gb18030'
        return r.text
    except:
        return '异常'


if __name__ == '__main__':
    start_url = 'http://jbk.39.net/gnqzhz/zztz/'
    text = getHTMLText(start_url)
    tree = etree.HTML(text)
    content = tree.xpath('//p[@style="text-indent:2em;font-size:15px;font-weight:bold;"]')
    content1 = content[0]
    x= content1.xpath('following-sibling::p[1]/@style')
    print(x)
    # for item in x:
    #     print(item.xpath('string(.)') + '\n')
    #     break
